package com.dmjj.common.base;

import com.dmjj.common.redisc.RedisUtil;
import com.dmjj.common.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.http.HttpServletRequest;


/**
 * Description: BaseController <br/>
 * Project: meiduoduo-common <br/>
 * ClassName: BaseController <br/>
 * Copyright: Copyright (c) 2018 deshang <br/>
 * 
 * @author ZHENG.Q <br/>
 * @version 2.0 2018年5月29日上午10:45:30 <br/>
 *
 */
public class BaseController {

	@Autowired
	private HttpServletRequest request;
	@Autowired
	private RedisUtil redisUtils;

	/*@Autowired
	private ResultVOUtil<Object> resultObject;*/

	protected LoginEntity getUserInfo() {
		String token = request.getParameter("token")!=null?request.getParameter("token"):null;
		if(token==null||"".equals(token)){
			return null;
		}
		Boolean IsExistToken = redisUtils.hasKey(token);
		LoginEntity entity = null;
		if(IsExistToken&& redisUtils.get(token)!=null){
			entity = (LoginEntity) redisUtils.get(token);
		}
		return entity;
	}

	/**
	 * @Description 校验token中的机构信息是否为空
	 * @Author lililiang
	 * @Date 2018/10/28 14:15
	 * @Param []
	 * @Return com.deshang.meiduoduo.common.entity.Login
	 */
	protected ResultVO<Object> checkOrganId() {
		/*Login login = this.getUserInfo();
		if(login == null){
			return resultObject.error(ResultEnum.REQUEST_TOKEN_EXPIRED.getCode(), ResultEnum.REQUEST_TOKEN_EXPIRED.getMsg());
		}
		Long organId = login.getOrganId();
		if(organId == null){
			return resultObject.error(ResultEnum.TOKEN_NO_HAVE_ORGANID.getCode(), ResultEnum.TOKEN_NO_HAVE_ORGANID.getMsg());
		}*/
		return null;
	}

	/**
	 * @Description 校验token中的员工信息是否为空
	 * @Author lililiang
	 * @Date 2018/10/28 14:15
	 * @Param []
	 * @Return com.deshang.meiduoduo.common.entity.Login
	 */
	protected ResultVO<Object> checkStaffId() {
		/*Login login = this.getUserInfo();
		if(login == null){
			return resultObject.error(ResultEnum.REQUEST_TOKEN_EXPIRED.getCode(), ResultEnum.REQUEST_TOKEN_EXPIRED.getMsg());
		}
		Long staffId = login.getStaffId();
		if(staffId == null){
			return resultObject.error(ResultEnum.TOKEN_NO_HAVE_STAFFID.getCode(), ResultEnum.TOKEN_NO_HAVE_STAFFID.getMsg());
		}*/
		return null;
	}

	/**
	 * @Description 校验token中的员工信息和机构信息是否为空
	 * @Author lililiang
	 * @Date 2018/10/28 14:15
	 * @Param []
	 * @Return com.deshang.meiduoduo.common.entity.Login
	 */
	protected ResultVO<Object> checkOrganIdAndStaffId() {
		/*Login login = this.getUserInfo();
		if(login == null){
			return resultObject.error(ResultEnum.REQUEST_TOKEN_EXPIRED.getCode(), ResultEnum.REQUEST_TOKEN_EXPIRED.getMsg());
		}
		Long staffId = login.getStaffId();
		if(staffId == null){
			return resultObject.error(ResultEnum.TOKEN_NO_HAVE_STAFFID.getCode(), ResultEnum.TOKEN_NO_HAVE_STAFFID.getMsg());
		}
		Long organId = login.getOrganId();
		if(organId == null){
			return resultObject.error(ResultEnum.TOKEN_NO_HAVE_ORGANID.getCode(), ResultEnum.TOKEN_NO_HAVE_ORGANID.getMsg());
		}*/
		return null;
	}


}
